import { observable, action, makeObservable } from 'mobx';
import moment from "moment";
import { currentUser } from "@/services/auth";
import GlobalFunctions from '@/store/globalFunctions';

class ProjectModel {
    @observable id= 0;//
    @observable bill_date= moment();//--申请日期
    @observable code="";//--编码
    @observable name= "";//名称
    @observable customerid= "";//客户ID
    @observable neednum= 1;//需求数量
    @observable amount= 0;//挂靠费用
    @observable major= [];//需求专业
    @observable schooled="";//学历要求
    @observable certificate= [];//需求证书
    @observable location= "";//挂靠地点
    @observable socialsecurity= 0;//社保情况（无，有）
    @observable area= "";//社保地区
    @observable bytstatus= "已签";//敲定、 已签、带证报价
    @observable periodunit= "年";//期限单位
    @observable periods= 1;//期限
    @observable signingtime= null;//签约时间
    @observable expirationtime= null;//到期时间
    @observable status= 0;//审核状态:0 待审核、1 审核中、2 已审核
    @observable purpose= "";//证书用途
    @observable certificatestatus= "";//证书状态 不限，初始注册，转注册
    @observable locationneed= "";//证书地区要求 不限，附近省份，省内
    @observable messag= "";//备注
    @observable signatory= currentUser.id;//签约人
    @observable userid= currentUser.id;//录入人ID
    @observable orgunitid= currentUser.orgunit_id;//部门ID
    @observable contractcode= "";//合同编码
    @observable threeperson= "";
    @observable certificate1 = [];
    @observable certificate2 = [];
    @observable certificate3 = [];
    @observable certificate4 = [];
    @observable certificate5 = [];
    @observable certificate6 = [];
    @observable certificatelen = 1;
    @observable isnew= true;
    @observable isedit=true;
    @observable allow_col=[];
    @observable colcontrol=false;

    constructor(id) {
        this.id=id;
        makeObservable(this);
    }
    @action setCode(code) {
        this.code = code;
    }
    @action setName(name) {
        this.name = name;
    }
    @action setBilledit(item) {
        this.isedit = item.edit;
        this.allow_col = item.allow_col;
        this.colcontrol = item.colcontrol;
    }
    @action setBill_date(bill_date) {
        this.bill_date = bill_date;
    }
    @action setCustomerid(customerid) {
        this.customerid = customerid;
    }
    @action setNeednum(neednum) {
        this.neednum = neednum;
    }
    @action setAmount(amount) {
        this.amount = amount;
    }
    @action setMajor(major) {
        this.major = major;
    }
    @action setSchooled(schooled) {
        this.schooled = schooled;
    }
    @action setCertificate(certificate) {
        this.certificate = certificate;
    }
    @action setLocation(location) {
        this.location = location;
    }
    @action setSocialsecurity(socialsecurity) {
        this.socialsecurity = socialsecurity;
    }
    @action setArea(area) {
        this.area = area;
    }

    @action setBytstatus(bytstatus) {
        this.bytstatus = bytstatus;
    }
    @action setPeriodunit(periodunit) {
        this.periodunit = periodunit;
    }
    @action setPeriods(periods) {
        this.periods = periods;
    }
    @action setSigningtime(signingtime) {
        this.signingtime = signingtime;
    }
    @action setExpirationtime(expirationtime) {
        this.expirationtime = expirationtime;
    }
    @action setStatus(status) {
        this.status = status;
    }
    @action setPurpose(purpose) {
        this.purpose = purpose;
    }
    @action setCertificatestatus(certificatestatus) {
        this.certificatestatus = certificatestatus;
    }
    @action setLocationneed(locationneed) {
        this.locationneed = locationneed;
    }
    @action setMessag(messag) {
        this.messag = messag;
    }
    @action setSignatory(signatory) {
        this.signatory = signatory;
    }
    @action setUserid(userid) {
        this.userid = userid;
    }
    @action setOrgunitid(orgunitid) {
        this.orgunitid = orgunitid;
    }
    @action setContractcode(contractcode) {
        this.contractcode = contractcode;
    }
    @action setThreeperson(threeperson) {
        this.threeperson = threeperson;
    }
    @action setCertificate1(certificate1) {
        this.certificate1 = certificate1;
    }
    @action setCertificate2(certificate2) {
        this.certificate2 = certificate2;
    }
    @action setCertificate3(certificate3) {
        this.certificate3 = certificate3;
    }
    @action setCertificate4(certificate4) {
        this.certificate4 = certificate4;
    }
    @action setCertificate5(certificate5) {
        this.certificate5 = certificate5;
    }
    @action setCertificate6(certificate6) {
        this.certificate6 = certificate6;
    }
    @action setCertificatelen(certificatelen) {
        this.certificatelen = certificatelen;
    }

    static fromJS(obj) {
        let m =  new ProjectModel(obj.id);
        //m.id= obj.id ;
        m.bill_date= moment(obj.bill_date);//--申请日期
        m.code= obj.code ;//--编码
        m.name= obj.name;//名称
        m.customerid= obj.customerid;//客户ID
        m.neednum= obj.neednum ;//需求数量
        m.amount= obj.amount;//挂靠费用
        m.major= obj.major;//需求专业
        m.schooled= obj.schooled //学历要求
        m.certificate= obj.certificate;//需求证书
        m.location= obj.location;//挂靠地点
        m.socialsecurity= obj.socialsecurity;//社保情况（无，有）
        m.area= obj.area;//社保地区
        m.bytstatus= obj.bytstatus;//敲定、 已签、带证报价
        m.periodunit= obj.periodunit;//期限单位
        m.periods= obj.periods ;//期限
        m.signingtime = obj.signingtime ? (GlobalFunctions.isEmptyobj(obj.signingtime) ? null : moment(obj.signingtime)) : null;//签约时间
        m.expirationtime = obj.expirationtime ? (GlobalFunctions.isEmptyobj(obj.expirationtime) ? null : moment(obj.expirationtime)) : null;//到期时间
        m.status= obj.status//审核状态:0 待审核、1 审核中、2 已审核
        m.purpose= obj.purpose ;//证书用途
        m.certificatestatus= obj.certificatestatus ;//证书状态 不限，初始注册，转注册
        m.locationneed= obj.locationneed ;//证书地区要求 不限，附近省份，省内
        m.message= obj.message ;//备注
        m.signatory= obj.signatory ;//签约人
        m.userid= obj.userid ;//录入人ID
        m.orgunitid= obj.orgunitid ;//部门ID
        m.contractcode= obj.contractcode ;//合同编码
        m.threeperson= obj.threeperson ;
        if (obj.certificate.length > 0) {
            m.certificate1 = obj.certificate[0].split('-')
            m.certificatelen = obj.certificate.length;
        }
        if (obj.certificate.length > 1) {
            m.certificate2 = obj.certificate[1].split('-')
        }
        if (obj.certificate.length > 2) {
            m.certificate3 = obj.certificate[2].split('-')
        }
        if (obj.certificate.length > 3) {
            m.certificate4 = obj.certificate[3].split('-')
        }
        if (obj.certificate.length > 4) {
            m.certificate5 = obj.certificate[4].split('-')
        }
        if (obj.certificate.length > 5) {
            m.certificate6 = obj.certificate[5].split('-')
        }
        m.isnew= false;
        return m;
    }
}

export default ProjectModel;